# coding:utf-8
import os
import time
import threading
from concurrent.futures import ThreadPoolExecutor,Future

lock = threading.Lock()


def work(i):
    lock.acquire()
    print(i)
    time.sleep(1)
    lock.release()
    return 'result: %s, tid: %d' % (i, os.getpid())


if __name__ == '__main__':
    t = ThreadPoolExecutor(max_workers=2)
    results: list[Future] = []
    for i in range(20):
        result = t.submit(work, (i,))
        results.append(result)

    for res in results:
        print(res.result())
